package ee.ttu.karileet.serviceshop.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ee.ttu.karileet.serviceshop.dao.ServiceRequestDAO;
import ee.ttu.karileet.serviceshop.dao.ServiceRequestStatusTypeDAO;
import ee.ttu.karileet.serviceshop.model.ServiceRequest;
import ee.ttu.karileet.serviceshop.model.ServiceRequestStatusType;

@Service
public class ServiceRequestStatusTypeDAOImpl implements ServiceRequestStatusTypeDAO {
	
	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void insertServiceRequestStatusType(ServiceRequestStatusType serviceRequestStatusType) {
		sessionFactory.getCurrentSession().save(serviceRequestStatusType);
	}

	@Override
	public ServiceRequestStatusType getServiceRequestStatusTypeById(
			long serviceRequestStatusTypeId) {
		return (ServiceRequestStatusType) sessionFactory.
			      getCurrentSession().
			      get(ServiceRequestStatusType.class, serviceRequestStatusTypeId);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ServiceRequestStatusType> getServiceRequestStatusTypes() {
	    Criteria criteria = sessionFactory.
	    	      getCurrentSession().
	    	      createCriteria(ServiceRequestStatusType.class);
	    return criteria.list();
	}

}
